home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / tclib20.zip / DEMO.ZIP / DEMOADV.C next >
Text File  |  1988-12-03  |  5KB  |  124 lines

  1. /* demoadv.c  -  used for testing TCHK advanced date conversions */
  2.  
  3. #include <howard.h>
  4. #include <datehk.h>
  5. #include <dateadv.h>
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. void main(void)
  13.  
  14. void main(void)
  15. {
  16.     extern int _argc;
  17.     extern int **_argv;
  18.     char buff[80], temp[80], temp2[80];
  19.     double dbl, dbl2;
  20.     struct date today, d, d2;
  21.     struct ddate dd, dd2;
  22.     int stype, dtype;
  23.  
  24.     if (_argc<3) {
  25.         printf("DemoAdv is a demonstration program of the advanced date conversions of TCHK.\n\n");
  26.         printf("Usage:  demoadv stype dtype\n\n");
  27.         printf("    demoadv will convert today's date from stype format\n");
  28.         printf("    to dtype format. See TCHK.DOC for more details\n");
  29.         exit(1);
  30.     }
  31.  
  32.     stype = atoi(_argv[1]);
  33.     dtype = atoi(_argv[2]);
  34.     if (stype<1 || stype>43 || dtype<1 || dtype>43) {
  35.         printf("Invalid format (must be 1-43)\n");
  36.         exit(2);
  37.     }
  38.  
  39. /*  for this demo, I get today's date, convert it to format 1 (MM-DD-YY)
  40.     via a sprintf() and then convert it to format stype for the test of
  41.     date_convert(s,d,stype,dtype).                                      */
  42.  
  43.     getdate(&today);
  44.     sprintf(buff,"%2d-%2d-%2d",today.da_mon,today.da_day,today.da_year-1900);
  45.     printf("Today's date: %s     Stype %d:  ",buff,stype);
  46.     switch (stype) {
  47.         case 4:
  48.         case 5:
  49.         case 6:
  50.         case 7:
  51.         case 8:  { date_convert(buff,&dbl,1,stype);
  52.                    printf("%lf",dbl);
  53.                    switch (dtype) {
  54.                        case 4:
  55.                        case 5:
  56.                        case 6:
  57.                        case 7:
  58.                        case 8:  { date_convert(&dbl,&dbl2,1,dtype);  break; }
  59.                        case 9:  { date_convert(&dbl,&d2,1,dtype);    break; }
  60.                        case 10: { date_convert(&dbl,&dd2,1,dtype);   break; }
  61.                        default: { date_convert(&dbl,temp2,1,dtype); break; }
  62.                    }
  63.                    break;
  64.                  }
  65.         case 9:  { date_convert(buff,&d,1,stype);
  66.                    printf("%d %d %d",d.da_day,d.da_mon,d.da_year);
  67.                    switch (dtype) {
  68.                        case 4:
  69.                        case 5:
  70.                        case 6:
  71.                        case 7:
  72.                        case 8:  { date_convert(&d,&dbl2,1,dtype);  break; }
  73.                        case 9:  { date_convert(&d,&d2,1,dtype);    break; }
  74.                        case 10: { date_convert(&d,&dd2,1,dtype);   break; }
  75.                        default: { date_convert(&d,temp2,1,dtype); break; }
  76.                    }
  77.                    break;
  78.                  }
  79.         case 10: { date_convert(buff,&dd,1,stype);
  80.                    printf("%d %d %d",dd.dday,dd.dmon,dd.dyear);
  81.                    switch (dtype) {
  82.                        case 4:
  83.                        case 5:
  84.                        case 6:
  85.                        case 7:
  86.                        case 8:  { date_convert(&dd,&dbl2,1,dtype);  break; }
  87.                        case 9:  { date_convert(&dd,&d2,1,dtype);    break; }
  88.                        case 10: { date_convert(&dd,&dd2,1,dtype);   break; }
  89.                        default: { date_convert(&dd,temp2,1,dtype); break; }
  90.                    }
  91.                    break;
  92.                  }
  93.         default: { date_convert(buff,temp,1,stype);
  94.                    printf("%s",temp);
  95.                    switch (dtype) {
  96.                        case 4:
  97.                        case 5:
  98.                        case 6:
  99.                        case 7:
  100.                        case 8:  { date_convert(temp,&dbl2,1,dtype);  break; }
  101.                        case 9:  { date_convert(temp,&d2,1,dtype);    break; }
  102.                        case 10: { date_convert(temp,&dd2,1,dtype);   break; }
  103.                        default: { date_convert(temp,temp2,1,dtype); break; }
  104.                    }
  105.                    break;
  106.                  }
  107.     }
  108.     printf("   ->   Dtype %d:  ",dtype);
  109.     switch (dtype) {
  110.         case 4:
  111.         case 5:
  112.         case 6:
  113.         case 7:
  114.         case 8:  { printf("%lf",dbl2);  break; }
  115.         case 9:  { printf("%d %d %d",d2.da_day,d2.da_mon,d2.da_year);  break; }
  116.         case 10: { printf("%d %d %d",dd2.dday,dd2.dmon,dd2.dyear);  break; }
  117.         default: { printf("%s",temp2);  break; }
  118.     }
  119.     printf("\n");
  120.  
  121. /* quit */
  122.     exit(0);
  123. }
  124.